package 每日一题;

/**
 * @author 会玩的洋洋
 * https://leetcode-cn.com/problems/reverse-prefix-of-word/
 */
public class _2000_反转单词前缀 {
    public String reversePrefix(String word, char ch) {
        String prefix = "", suffix = "";
        int index = 0;
        for (int i = 0; i < word.length(); i++) {
            if (word.charAt(i) == ch) {
                prefix = word.substring(0, i + 1);
                index = i + 1;
                break;
            }
        }
        suffix = word.substring(index);
        StringBuilder sb = new StringBuilder(prefix);
        sb.reverse();
        sb.append(suffix);
        return sb.toString();
    }
}
